﻿
@page
@model AdminUI.Pages.Finance.BillModel
@{
    var F = Html.F();
}

@section body {
    <f:Panel ID="Panel1" BodyPadding="5" ShowBorder="false" Layout="VBox" ShowHeader="false" IsViewPort="true">
        <Items>
            <f:Grid ID="Grid1" BoxFlex="1" ShowBorder="true" ShowHeader="false" EnableTextSelection="true" EnableColumnLines="true"  AllowSorting="true" AllowPaging="true" IsDatabasePaging="true"
                    DataIDField="BillID" DataTextField="BillID" SortField="BillID" SortDirection="DESC" PageSize="@ViewBag.PageSize" RecordCount="@ViewBag.Total" DataSource="@ViewBag.DataSource" 
                    OnSort="@Url.Handler("Grid_DoAction")" OnSortFields="Panel1" OnPageIndexChanged="@Url.Handler("Grid_DoAction")" OnPageIndexChangedFields="Panel1">
                <Toolbars>
                    <f:Toolbar ID="Toolbar1" ToolbarAlign="Right" ItemSpace="1">
                        <Items>
                            @*<f:Button ID="btnAdd" IconAlign="Left" EnableDefaultState="false" IconFont="_Plus" Text="新增" OnClientClick="onAddClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnEdit" IconAlign="Left" EnableDefaultState="false" IconFont="_Edit" Text="编辑" OnClientClick="onEditClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>*@
        @*                     <f:Button ID="btnClearing" IconAlign="Left" Hidden="@Model.OnlineTID > 0" EnableDefaultState="false" IconFont="Rmb" Text="结算" OnClientClick="onClearingClick();"></f:Button>
                            <f:ToolbarSeparator Hidden="@Model.OnlineTID > 0"></f:ToolbarSeparator> *@
                            <f:Button ID="btnRefresh" IconAlign="Left" EnableDefaultState="false" IconFont="_Refresh" Text="刷新" OnClientClick="onRefreshClick();"></f:Button>
                            <f:ToolbarFill ID="ToolbarFill1"></f:ToolbarFill>
                            <f:DropDownList ID="ddlCondition" SelectedValue="" Width="150">
                                <f:ListItem Text="== 请选择条件 ==" Value="" />
                                <f:ListItem Text="会员ID" Value="UserID" />
                                <f:ListItem Text="会员姓名" Value="TrueName" />
                                <f:ListItem Text="手机号" Value="Mobile" />
                            </f:DropDownList>
                            <f:TriggerBox ID="ttbSearch" ShowLabel="false" EmptyText="请输入搜索关键字" TriggerIcon="Search" OnTriggerClick="@Url.Handler("Grid_DoAction")" OnTriggerClickFields="Panel1"
                                          OnTriggerClickParameter1="@(new Parameter("actionType", "search", ParameterMode.String))"
                                          OnTriggerClickParameter2="@(new Parameter("searchText", "F.ui.ttbSearch.getValue()"))"
                                          OnTriggerClickParameter3="@(new Parameter("searchCondition", "F.ui.ddlCondition.getValue()"))">
                            </f:TriggerBox>
                        </Items>
                    </f:Toolbar>
                </Toolbars>
                <Columns>
                    @*<f:RowNumberField HeaderText="#" TextAlign="Center" />*@
                    <f:RenderField HeaderText="账单ID" DataField="BillID" FieldType="Int" Width="100" TextAlign="Center" Hidden="false" />
                    @* <f:RenderField HeaderText="租户" DataField="TID" FieldType="Int" Hidden="@Model.OnlineTID > 0" Width="60" /> *@
                    <f:RenderField HeaderText="会员" DataField="UserID" FieldType="Int" Width="180" RendererFunction="renderMember" />
                    <f:RenderField HeaderText="会员姓名" DataField="TrueName" Width="100" Hidden="true"/>
                    <f:RenderField HeaderText="类型" DataField="BillType" FieldType="Int" Width="100" TextAlign="Center" RendererFunction="renderBillType" />
                    @* <f:RenderField HeaderText="销售区域" DataField="AreaID" FieldType="Int" Width="80" TextAlign="Center" /> *@
                    <f:RenderField HeaderText="关联会员" DataField="RelationUserID" FieldType="Int" Width="180" RendererFunction="renderRelationMember" />
                    <f:RenderField HeaderText="关联用户名" DataField="RelationUserName" Width="100" Hidden="true" />
                    <f:RenderField HeaderText="关联订单ID" DataField="RelationOrderID" FieldType="Int" Width="160" TextAlign="Center" />
                    <f:RenderField HeaderText="关联订单金额" DataField="RelationOrderAmount" FieldType="Double" Width="120" TextAlign="Right" />
                    <f:RenderField HeaderText="账单金额" DataField="Amount" FieldType="Double" Width="100" TextAlign="Right" />
                    <f:RenderField HeaderText="结算日期" DataField="ClearingDate" FieldType="Date" Renderer="Date" RendererArgument="yyyy-MM-dd" Width="100" TextAlign="Center" />
                    <f:RenderField HeaderText="备注" DataField="Memo" MinWidth="100" ShowToolTip="true" ExpandUnusedSpace="true" />
                </Columns>
                <PageItems>
                    <f:ToolbarSeparator></f:ToolbarSeparator>
                    <f:ToolbarText Text="每页记录数："></f:ToolbarText>
                    <f:DropDownList ID="ddlGridPageSize" Width="60" SelectedValue="@ViewBag.PageSize" OnSelectedIndexChanged="@Url.Handler("Grid_DoAction")" OnSelectedIndexChangedParameter1="@(new Parameter("actionType","changePageSize",ParameterMode.String))" OnSelectedIndexChangedFields="Panel1">
                        <Items>
                            <f:ListItem Text="10" Value="10"></f:ListItem>
                            <f:ListItem Text="20" Value="20"></f:ListItem>
                            <f:ListItem Text="30" Value="30"></f:ListItem>
                            <f:ListItem Text="50" Value="50"></f:ListItem>
                            <f:ListItem Text="100" Value="100"></f:ListItem>
                            <f:ListItem Text="200" Value="200"></f:ListItem>
                        </Items>
                    </f:DropDownList>
                </PageItems>
            </f:Grid>
        </Items>
    </f:Panel>
    
    <f:Window ID="Window1" IsModal="true" Hidden="true" Target="Top" EnableResize="true" EnableMaximize="true" EnableIFrame="true" Width="750" Height="500">
        @*<Listeners>
            <f:Listener Event="close" Handler="onWindowClose('refresh');"></f:Listener>
        </Listeners>*@
    </f:Window>
}

@section script {
	<script src="~/res/js/grid.js"></script>
	<script>
	/*
		//关闭弹窗后刷新当前页面
        function onWindowClose(actionType, actionParams) {
            var params = {
                //nodeId: getNodeId()
            };
            
            if(actionType) params.actionType = actionType;
            if(actionParams) $.extend(params, actionParams);// 加入扩展参数
           
            F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', params); // 触发后台事件
        }
	*/
        
        function onRefreshClick() {
            var grid1 = F.ui.Grid1;
            var selectedRows = grid1.getSelectedRows();
            F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                actionType: 'refresh',
                selectedIDs: selectedRows
            });
        }

        function renderMember(value, params) {
            return F.formatString('{0}-{1}', value, params.rowData.values.TrueName);
        }

        function renderRelationMember(value, params) {
            return F.formatString('{0}-{1}', value, params.rowData.values.RelationUserName);
        }

        function renderBillType(value, params) {
            switch (value) { //账单类型：1-业务奖励，2-团队奖励，9-业绩提成
                case 1:
                    return "<span class='tag-c1'>业务奖励</span>";
                case 2:
                    return "<span class='tag-c2'>团队奖励</span>";
                case 9:
                    return "<span class='tag-c5'>业绩提成</span>";
                default:
                    return "";
            }
        }

	</script>
}